﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web.UI.WebControls;
using Module.DataAccess;
using Module.EntitiesInfo;

namespace Module.BusinessLogic
{
    public class CMSClubName
	{		
		public static int Insert(CMSClubNameInfo cMSClubNameInfo)
		{
			try
			{
                DataCach.DataCach cache = new DataCach.DataCach();
                cache.RemoveAll();
				return new CMSClubNameDB().Insert(cMSClubNameInfo);
			}
			catch (Exception ex)
			{
				throw;
			}

		}
		
		public static void Update(CMSClubNameInfo cMSClubNameInfo)
		{
			try
			{
				new CMSClubNameDB().Update(cMSClubNameInfo);
                DataCach.DataCach cache = new DataCach.DataCach();
                cache.RemoveAll();
			}
			catch (Exception ex)
			{
				throw;
			}

		}
		
		public static void Delete(int clubId)
		{
			try
			{
				new CMSClubNameDB().Delete(clubId);
                DataCach.DataCach cache = new DataCach.DataCach();
                cache.RemoveAll();
			}
			catch (Exception ex)
			{
				throw;
			}

		}

        public static CMSClubNameInfo GetInfo(int id)
        {
            try
            {
                CMSClubNameInfo info;
                info = ObjectHelper.FillObject<CMSClubNameInfo>(new CMSClubNameDB().GetInfo(id));
                if (info != null)
                    return info;
                return null;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static CMSClubNameInfo GetInfoInsite(int id)
        {
            try
            {
                DataCach.DataCach cache = new DataCach.DataCach();
                string strCache = id + "_{18E61898-97E1-4568-96FD-F83765C6E5E7}";
                CMSClubNameInfo info=new CMSClubNameInfo();
                if (cache.GetCache(strCache) != null)
                {
                    info = (CMSClubNameInfo)(cache.GetCache(strCache));
                    return info;
                }
                info = ObjectHelper.FillObject<CMSClubNameInfo>(new CMSClubNameDB().GetInfo(id));
                if (info !=null)
                {
                    cache.InsertCache(strCache, info,
                                      Convert.ToDouble(ConfigurationSettings.AppSettings["timeCache"].ToString()));
                }
                return info;                                             
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static DataTable GetAll(int param,int type)
        {
            try
            {
                return new CMSClubNameDB().GetAll(param,type);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static void FillDropList(ListControl ctrlList, string selectedValue)
        {
            try
            {
                DataTable dt = new DataTable();
                dt = GetAll(0,2);
                ctrlList.Items.Insert(0, new ListItem("--------Lựa chọn câu lạc bộ --------", "0"));
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                       
                        ListItem _item = new ListItem(dr["ClubName"].ToString(), dr["ClubId"].ToString());
                        if (_item.Value == selectedValue) _item.Selected = true;
                        ctrlList.Items.Add(_item);
                    }
                }

            }
            catch (Exception ex)
            {
                throw;
            }
        }
       

        public static int GetCount(string keysearch, int status, DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow)
        {
            try
            {
                return new CMSClubNameDB().GetCount(keysearch, status, starDatetime, endDatetime, beginRow, endRow);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static DataTable Search(string keysearch, int status, DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow, string orderByColumn)
        {
            try
            {
                return new CMSClubNameDB().Search(keysearch, status, starDatetime, endDatetime, beginRow, endRow, orderByColumn);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public static void UpdateStatus(int clubId, int status, int param)
        {
            try
            {
                new CMSClubNameDB().UpdateStatus(clubId, status, param);
            
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static int GetCount()
        {
            try
            {
                DataCach.DataCach cache = new DataCach.DataCach();
                string strCache = "{2F2D88FD-6659-4506-8241-1E28FB4634CA}";
                int count = 0;
                if (cache.GetCache(strCache) != null)
                {
                    count = (int)(cache.GetCache(strCache));
                    return count;
                }
                count=new CMSClubNameDB().GetCount();
                if (count > 0)
                {
                    cache.InsertCache(strCache, count,
                                      Convert.ToDouble(ConfigurationSettings.AppSettings["timeCache"].ToString()));
                }
                return count;
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static DataTable Getlist(int beginRow, int endRow, string orderByColumn)
        {
            try
            {
                DataCach.DataCach cache = new DataCach.DataCach();
                string strCache =beginRow + "_" + endRow + "_" + orderByColumn+ "{D9E0E317-B15B-4106-9EFC-9405FD749A24}";
                DataTable dt = new DataTable();
                if (cache.GetCache(strCache) != null)
                {
                    dt = (DataTable)(cache.GetCache(strCache));
                    return dt;
                }
                dt = new CMSClubNameDB().Getlist(beginRow, endRow, orderByColumn);
                if (dt != null && dt.Rows.Count > 0)
                {
                    cache.InsertCache(strCache, dt, Convert.ToDouble(ConfigurationSettings.AppSettings["timeCache"].ToString()));
                }
                return dt;
                
            }
            catch (Exception ex)
            {
                throw;
            }

        }
	}
}
